package com.example.tetris.Tetris;

import com.example.tetris.Tetris.TetrisBorder;
import ohos.aafwk.ability.Ability;
import ohos.agp.components.Component;
//单击游戏界面时旋转方块，如果超出边界则不会旋转
public class TetrisEvent extends TetrisBorder {


    public TetrisEvent(Ability ability, Component component, int[][] drawBlock) {
        super(ability, component, drawBlock);
    }
    public TetrisEvent(Ability ability, Component component) {
        super(ability, component);

        component.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                //游戏未开始，返回
                if(!isPlaying){
                    return;
                }
                //得到旋转后的方块
                int [][] block = rotateBlock(currentBlock,blockCurrentOrientation+1);
                //判断是否可以旋转
                int result = verifyBlockLocation(block,blockCurrentRow,blockCurrentCol);
                //如果可以旋转
                if(result==TETRIS_BLOCK_CONTINUE){
                    //将旋转后的方块当作当前块
                    currentBlock = block;
                    //让UI刷新，也就是调用onDraw方法
                    component.invalidate();
                }
            }
        });
    }
}
